#include "main-window.h"
#include "ui_main-window.h"

MainWindow::MainWindow(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::MainWindow)
{
    initUi();

    initData();

    initUiData();

    initConnect();
}

MainWindow::~MainWindow()
{
    delete ui;

    delete start_game_scene;

    delete select_level_scene;
}


void MainWindow::initUi()
{
    ui->setupUi(this);

    this->start_game_scene = new StartGameScene(this);

    this->select_level_scene = new SelectLevelScene(this);
}


void MainWindow::initData()
{
    this->start_game_scene->show();

    this->select_level_scene->hide();
}

void MainWindow::initUiData()
{
    // 设置窗口固定大小
    this->setFixedSize(315, 560);

    // 设置窗口标题
    this->setWindowTitle("Coin Flip");

    // 设置窗口图标
    this->setWindowIcon(QPixmap(GOLD_COIN));
}

void MainWindow::initConnect()
{
    connect(this->start_game_scene->start_button, &QPushButton::clicked, this, [=]() {
        QTimer::singleShot(300, this, [=]() {
            this->start_game_scene->hide();

            this->select_level_scene->show();
        });
    });

    connect(this->select_level_scene->back_button,&QPushButton::clicked, this, [=]() {
        QTimer::singleShot(300, this, [=]() {
            this->start_game_scene->show();

            this->select_level_scene->hide();
        });
    });
}
